<template>
  <div>
    <div class="category-header">
      <span>销售额类别占比</span>
      <el-radio-group v-model="value" size="mini">
        <el-radio-button label="全部渠道" />
        <el-radio-button label="线上" />
        <el-radio-button label="门店" />
      </el-radio-group>
    </div>
    <div ref="charts" class="charts" />
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Category',
  data() {
    return {
      value: '全部渠道'
    }
  },
  mounted() {
    const pieCharts = echarts.init(this.$refs.charts)
    pieCharts.setOption({
      title: {
        text: 'Search Engine',
        subtext: 1048,
        left: 'center',
        top: 'center'
      },
      // tooltip: {
      //   trigger: 'item'
      // },
      // legend: {
      //   top: '5%',
      //   left: 'center'
      // },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: true,
            position: 'outside'
          },
          // emphasis: {
          //   label: {
          //     show: true,
          //     fontSize: 40,
          //     fontWeight: 'bold'
          //   }
          // },
          labelLine: {
            show: true
          },
          data: [
            { value: 1048, name: 'Search Engine' },
            { value: 735, name: 'Direct' },
            { value: 580, name: 'Email' },
            { value: 484, name: 'Union Ads' },
            { value: 300, name: 'Video Ads' }
          ]
        }
      ]
    })
    // 绑定事件
    pieCharts.on('mouseover', (params) => {
      const { name, value } = params
      pieCharts.setOption({
        title: {
          text: name,
          subtext: value
        }
      })
    })
  }
}
</script>

<style scoped>
.category-header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #d9d9d9;
  padding: 10px 0px 15px 0px;
}
>>>.el-radio-button--mini .el-radio-button__inner {
    padding: 2px 15px;
}
.charts{
  width: 100%;
  height: 310px;
}
</style>
